package loot;

import util.Func;
import util.util.Hist;

public class HordeTable extends LootTable {
	//
	// Make the rolls, then get the loot
	//

	private Hist<String>	pass1 = new Hist<String>();
	private Hist<String>	pass2 = new Hist<String>();
	
	public Hist<String> getLoot(int level) {
		//
		// In order to get a proper value from this loot table. Yuo are suppossed to roll twice for each catagory
		//
		Hist<String>	LL = new Hist<String>();
		
		addCopper(				level + pass1.get("addCopper").intValue()				,LL);
		addSilverAndElectrum(	level + pass1.get("addSilverAndElectrum").intValue()	,LL);
		addGold(				level + pass1.get("addGold").intValue()					,LL);
		addPlatinum(			level + pass1.get("addPlatinum").intValue()				,LL);
		addGems(				level + pass1.get("addGems").intValue()					,LL);
		addArt(					level + pass1.get("addArt").intValue()					,LL);
		addMagicItems(			level + pass1.get("addMagicItems").intValue()			,LL);

		addCopper(				level + pass2.get("addCopper").intValue()				,LL);
		addSilverAndElectrum(	level + pass2.get("addSilverAndElectrum").intValue()	,LL);
		addGold(				level + pass2.get("addGold").intValue()					,LL);
		addPlatinum(			level + pass2.get("addPlatinum").intValue()				,LL);
		addGems(				level + pass2.get("addGems").intValue()					,LL);
		addArt(					level + pass2.get("addArt").intValue()					,LL);
		addMagicItems(			level + pass2.get("addMagicItems").intValue()			,LL);

		return LL;
	}
	
	public void addCopper(int R, Hist<String> LL) {
		if (R >= 8)					{	LL.add("copper pieces", Func.roll(2,10)*100);		}
	}
	public void addSilverAndElectrum(int R, Hist<String> LL) {
		if (R >= 7 && R <= 16)		{	LL.add("silver pieces", Func.roll(2,10)*10);		}
		if (R >= 17)				{	LL.add("electrum pieces", Func.roll(10)*100);		}
	}
	public void addGold(int R, Hist<String> LL) {
		if (R >= 12)				{	LL.add("gold pieces", Func.roll(10)*10);			}
	}
	public void addPlatinum(int R, Hist<String> LL) {
		if (R >= 16)				{	LL.add("platinum pieces", Func.roll(2,10));			}		
	}
	public void addGems(int R, Hist<String> LL) {
		if (R >= 13 && R <= 22)		{	LL.add("ornamental gems", Func.roll(2,10));			}
		if (R >= 23 && R <= 26)		{	LL.add("semiprecious gems", Func.roll(2,10));		}
		if (R >= 27)				{	LL.add("precious gems", Func.roll(2,10));			}
	}
	public void addArt(int R, Hist<String> LL) {
		if (R >= 23 && R <= 26)		{	LL.add("decorative art objects", Func.roll(2,10));	}
		if (R >= 27)				{	LL.add("fine art objects", Func.roll(2,8));			}
	}
	public void addMagicItems(int R, Hist<String> LL) {
		if (R >= 16 && R <= 21)		{	LL.add("common potion", Func.roll(2,4));			}
		if (R >= 22 && R <= 24)		{	LL.add("uncommon magic item", Func.roll(3));		}
		if (R >= 25 && R <= 27)		{	LL.add("rare magic item", Func.roll(2));			}
		if (R >= 28 && R <= 30)		{	LL.add("very rare magic item", 1);					}
		if (R >= 31 && R <= 35)		{	LL.add("legendary magic item", 1);					}
		if (R >= 36)				{	LL.add("artifact", 1);								}
	}

	@Override
	public void makeRolls() {
		pass1.put("addCopper", Func.roll(20));
		pass1.put("addSilverAndElectrum", Func.roll(20));
		pass1.put("addGold", Func.roll(20));
		pass1.put("addPlatinum", Func.roll(20));
		pass1.put("addGems", Func.roll(20));
		pass1.put("addArt", Func.roll(20));
		pass1.put("addMagicItems", Func.roll(20));
		
		pass2.put("addCopper", Func.roll(20));
		pass2.put("addSilverAndElectrum", Func.roll(20));
		pass2.put("addGold", Func.roll(20));
		pass2.put("addPlatinum", Func.roll(20));
		pass2.put("addGems", Func.roll(20));
		pass2.put("addArt", Func.roll(20));
		pass2.put("addMagicItems", Func.roll(20));
	}
}
